﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using KeRui.Common;
using System.Collections.Generic;

public partial class Manage_Menu : System.Web.UI.Page
{
    public string Act = ManageHelper.PageAct();
    public string ActName = Utils.UrlDecode(PageRequest.GetString("actname").Trim(), "UTF-8");
    public int SiteID = PageRequest.GetInt("siteid", -1);

    public List<KeRui.Model.AdminFlag> listFlag;
    public List<KeRui.Model.CmsServer> listServer;
    public List<KeRui.Model.CmsSite> listSite;

    public KeRui.Model.CmsSite modelSite;

    public int Type = PageRequest.GetInt("flagType", 0);
    protected void Page_Load(object sender, EventArgs e)
    {
        ManageHelper.CheckAdminLogin("menu");

        if (SiteID > 0 && Act == "")
        {
            KeRui.BLL.CmsSite bllSite = new KeRui.BLL.CmsSite();
            modelSite = bllSite.GetModel(SiteID);
            if (modelSite == null)
                modelSite = new KeRui.Model.CmsSite();
        }

    }

    #region 显示服务器和站点列表
    public void SiteShow()
    {
        int sitecount = 0;
        string urlss = "";
        KeRui.BLL.CmsServer bllServer = new KeRui.BLL.CmsServer();
        KeRui.BLL.CmsSite bllSite = new KeRui.BLL.CmsSite();
        foreach (KeRui.Model.CmsServer server in bllServer.GetList(-1))
        {

            string xs = "";
            bool flag = true;
            xs += @"<tr style='display:' treeItemLevel='1' class='tdbg' onmouseover=""this.className='tdbg-dark';"" onmouseout=""this.className='tdbg';""><td nowrap>";
            xs += @"<img align=""absmiddle"" style=""cursor:pointer;"" onClick=""displayChildren(this);"" isOpen=""true"" src=""pic/tree/minus.gif"" />";
            xs += @"<img align=""absmiddle"" src=""pic/menu/machine.gif""/>&nbsp;" + server.ServerName;
            xs += "</td></tr>\r\n\r\n";
            foreach (KeRui.Model.CmsSite site in bllSite.GetList(server.ServerID, 1))
            {

                if (ManageHelper.CheckAdminHavePower("site_" + site.SiteID))
                {
                    if (flag)
                    {
                        Response.Write(xs);
                        flag = false;
                    }
                    Response.Write(@"<tr style='display:' treeItemLevel='2' class='tdbg' onmouseover=""this.className='tdbg-dark';"" onmouseout=""this.className='tdbg';""><td nowrap>");
                    Response.Write(@"<img align=""absmiddle"" src=""pic/tree/empty.gif""/><img align=""absmiddle"" src=""pic/tree/empty.gif""/>");
                    Response.Write(@"<a href='" + site.SiteUrl + @"' target='_blank' title='点击进入站点首页'><img align=""absmiddle"" src=""pic/menu/site.gif""/></a>&nbsp;<a href='" + server.ServerUrl + "/manage/main.aspx?sitemenu=" + site.SiteID + @"&actname=" + site.SiteName + @"' target='_top' onclick='openFolderByA(this);' isTreeLink='true'>" + site.SiteName + "</a>");
                    Response.Write(@"&nbsp;<a href='" + server.ServerUrl + "/manage/main.aspx?siteid=" + site.SiteID + @"' title='单独管理模式' target='_blank' onclick='openFolderByA(this);' isTreeLink='true'><img align=""absmiddle"" src=""pic/icons/url.gif""/></a>");
                    //Response.Write(@"&nbsp;<a href='javascript:' title='单独管理模式' target='top' onclick='gotoMain("+site.SiteID+@");' isTreeLink='true'><img align=""absmiddle"" src=""pic/icons/url.gif""/></a>");
                    Response.Write("</td></tr>\r\n\r\n");
                    urlss = server.ServerUrl + "/manage/main.aspx?sitemenu=" + site.SiteID + @"&actname=" + site.SiteName;
                    sitecount++;
                }
            }
            if (sitecount == 1)
            {
                Response.Write("<script type=\"text/javascript\">window.parent.location.href='" + urlss + @"';</script>");
            }
        }
    }
    #endregion

    #region 0ld
    //public void SiteShow()
    //{
    //    KeRui.BLL.CmsServer bllServer = new KeRui.BLL.CmsServer();
    //    KeRui.BLL.CmsSite bllSite = new KeRui.BLL.CmsSite();
    //    foreach (KeRui.Model.CmsServer server in bllServer.GetList(-1))
    //    {
    //        Response.Write(@"<tr style='display:' treeItemLevel='1' class='tdbg' onmouseover=""this.className='tdbg-dark';"" onmouseout=""this.className='tdbg';""><td nowrap>");
    //        Response.Write(@"<img align=""absmiddle"" style=""cursor:pointer;"" onClick=""displayChildren(this);"" isOpen=""true"" src=""pic/tree/minus.gif"" />");
    //        Response.Write(@"<img align=""absmiddle"" src=""pic/menu/machine.gif""/>&nbsp;" + server.ServerName);
    //        Response.Write("</td></tr>\r\n\r\n");
    //        foreach (KeRui.Model.CmsSite site in bllSite.GetList(server.ServerID, -1))
    //        {
    //            if (ManageHelper.CheckAdminHavePower("site_" + site.SiteID))
    //            {
    //                Response.Write(@"<tr style='display:' treeItemLevel='2' class='tdbg' onmouseover=""this.className='tdbg-dark';"" onmouseout=""this.className='tdbg';""><td nowrap>");
    //                Response.Write(@"<img align=""absmiddle"" src=""pic/tree/empty.gif""/><img align=""absmiddle"" src=""pic/tree/empty.gif""/>");
    //                Response.Write(@"<a href='" + site.SiteUrl + @"' target='_blank' title='点击进入站点首页'><img align=""absmiddle"" src=""pic/menu/site.gif""/></a>&nbsp;<a href='" + server.ServerUrl + "/manage/main.aspx?sitemenu=" + site.SiteID + @"&actname=" + site.SiteName + @"' target='_top' onclick='openFolderByA(this);' isTreeLink='true'>" + site.SiteName + "</a>");
    //                Response.Write(@"&nbsp;<a href='" + server.ServerUrl + "/manage/main.aspx?siteid=" + site.SiteID + @"' title='单独管理模式' target='_blank' onclick='openFolderByA(this);' isTreeLink='true'><img align=""absmiddle"" src=""pic/icons/url.gif""/></a>");
    //                //Response.Write(@"&nbsp;<a href='javascript:' title='单独管理模式' target='top' onclick='gotoMain("+site.SiteID+@");' isTreeLink='true'><img align=""absmiddle"" src=""pic/icons/url.gif""/></a>");
    //                Response.Write("</td></tr>\r\n\r\n");
    //            }
    //        }
    //    }
    //}
    #endregion

    #region 显示站点下的清单类表
    public void MenuShow(int ParentID, bool IsDisplay, int LevelNum)
    {
        KeRui.BLL.AdminFlag bllFlag = new KeRui.BLL.AdminFlag();

        if (LevelNum < 1)
            LevelNum = 1;

        int FlagType = (SiteID > 0 ? 1 : Type);
        string FlagAction = (LevelNum == 1 ? Act : "");

        listFlag = bllFlag.GetList(ParentID, FlagType, 1, FlagAction);
        foreach (KeRui.Model.AdminFlag model in listFlag)
        {
            if (model.Icon == "")
                model.Icon = "item.gif";
            if (model.AppUrl == "")
                model.AppUrl = "welcome.aspx";
            //权限判断
            if (SiteID != -1)
            {
                model.Flag = model.Flag + "_" + SiteID;
            }
            if (!ManageHelper.CheckAdminHavePower(model.Flag))
            {
                Response.Write("");
                //MenuShow(model.ID, model.IsOpen, LevelNum + 1);
            }
            else
            {

                Response.Write(@"<tr style='display:");
                if (!IsDisplay)
                    Response.Write("none");
                Response.Write("' ");

                Response.Write(@"treeItemLevel='" + LevelNum + @"' class='tdbg' onmouseover=""this.className='tdbg-dark';"" onmouseout=""this.className='tdbg';""><td nowrap>");

                string rn = "";

                if (!model.HaveChildNav)//没下属
                {
                    for (int emptyNum = 0; emptyNum < LevelNum; emptyNum++)
                    {
                        Response.Write(rn + @"<img align=""absmiddle"" src=""pic/tree/empty.gif""/>");
                    }
                    Response.Write(rn + @"<img align=""absmiddle"" src=""pic/menu/" + model.Icon + @"""/>&nbsp;<a href='" + (SiteID == -1 ? model.AppUrl : model.AppUrl.Replace("{@siteid}", SiteID.ToString())) + "' target='right' onclick='openFolderByA(this);' isTreeLink='true'>" + model.FlagName + "</a>");
                    Response.Write(rn + "</td></tr>\r\n\r\n");
                }
                else
                {
                    for (int emptyNum = 0; emptyNum < LevelNum - 1; emptyNum++)
                    {
                        Response.Write(rn + @"<img align=""absmiddle"" src=""pic/tree/empty.gif""/>");
                    }
                    Response.Write(rn + @"<img align=""absmiddle"" style=""cursor:pointer;"" onClick=""displayChildren(this);"" isOpen=""" + model.IsOpen.ToString().ToLower() + @""" src=""pic/tree/" + (model.IsOpen ? "minus" : "plus") + @".gif"" />");
                    Response.Write(rn + @"<img align=""absmiddle"" src=""pic/menu/" + model.Icon + @"""/>&nbsp;" + model.FlagName);
                    Response.Write(rn + "</td></tr>\r\n\r\n");
                    MenuShow(model.ID, model.IsOpen, LevelNum + 1);
                }
            }
        }
    }
    #endregion

}
